<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>电商平台系统管理登录界面</title>
		<link rel="stylesheet" href="css/login.css" />
		<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
	</head>
	<body>
		<div class="login_lay">
	      <div>
	      	  SHOPPING
	      </div>
	      <div>
	      	<form action="login.user" method="post">
	      		<table>
	      			<tr>
	      				<td>用户名：</td>
	      				<td><input type="text" name="uname" id="uname"></td>
	      			</tr>
	      			<tr>
	      				<td>密&nbsp;&nbsp;&nbsp;码：</td>
	      				<td><input type="password" name="upwd" id="upwd"></td>
	      			</tr>
	      			<tr>
	      				<td colspan="2">
	      					<input type="submit" value="登录" onclick="return login();"/>
	      					<input type="reset" value="重置"/>	
	      				</td>	
	      			</tr>
	      		</table>
	      	</form>
	      </div>
	      <div>
	      	  &copy;2018-12-21 ly制作
	      </div>
		</div>
		<script type="text/javascript">
		/*   $(function(){
			  alert("测试jquery");
		  }) */
		  /* if(top.location!=self.location){
			  top.location=self.location
		  } */
		  
		  function login(){
			 var uname=$("#uname").val().trim();
			 var upwd=$("#upwd").val().trim();
			 var flag=true;
			 
			 if(uname.length==0){
				 alert("请输入用户名");
				 return false;
			 }
			 /* alert(upwd); */
			 if(upwd.length==0){
				 alert("请输入密码");
				 return false;
				 
			 }
			 //alert(uname+"  "+upwd);
			 //判断用户名
			 var data1={uname:uname};
			 flag=ajaxfun("checkname.user",data1,"用户名不存"); 
			
			 if(flag==false){
				 return flag;
			 }
			 
		
			 //判断密码
			  var data={uname:uname,upwd:upwd}
			 flag=ajaxfun("checkpwd.user",data,"密码不正确");
			 
			 
			 if(flag==false){
				 return flag;
			 }
			 //权限的判断
			
			 flag=ajaxfun("checklevel.user",data,"对不起，您没有权限登陆")
			 
			 
			 return flag;
			 
		 }
		
		
		function ajaxfun(url,data,restr){
			var flag=true;
			$.ajax({
				 url:url,
				 type:"get",
				 async:false,/*同步*/
				 data:data,
				 dataType:"json",
				 success:function(result){
					/*  alert("ceshi"+result); */
					if(result.flag==false){
						alert(restr);
						flag=false;
					}
					
				 },
				 error:function(){
					 alert("失败");
					 flag=false;
					
				 }
			 })
			 return flag;
		}
		
		</script>
		
	</body>
</html>
